package com.cnyz.controller;

import com.cnyz.base.ResponseResult;
import com.cnyz.dto.QuestionDto;
import com.cnyz.service.QuestionService;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/question")
@RestController
public class QuestionController {

    @Autowired
    private QuestionService questionService;

    @PostMapping("/add")
    @ApiOperation(value = "问题添加")
    public ResponseResult addQuestion(@RequestBody QuestionDto questionDto){
        questionService.addQuestion(questionDto);
        return ResponseResult.success();
    }

    @GetMapping("/page")
    @ApiOperation(value = "问题分页查询")
    public ResponseResult getQuestionPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                          @RequestParam(defaultValue = "10") Integer pageSize,
                                          @RequestParam(required = false) List<Long> questionIds,
                                          @RequestParam(required = false) String subject,
                                          @RequestParam(required = false) Integer type,
                                          @RequestParam(required = false) String file) {
        // 假设 questionService.getQuestionPage(page, size) 返回分页结果
        return ResponseResult.success(questionService.getQuestionPage(pageNum, pageSize, questionIds,subject, type, file));
    }

    @PostMapping("/adds")
    @ApiOperation(value = "问题批量添加")
    public ResponseResult addQuestions(@RequestBody List<QuestionDto> questionDtos){
        questionService.addQuestions(questionDtos);
       return ResponseResult.success();
    }

    @PostMapping("/update")
    @ApiOperation(value = "问题更新")
    public ResponseResult updateQuestion(@RequestBody QuestionDto questionDto) {
        questionService.updateQuestion(questionDto);
        return ResponseResult.success();
    }

}
